import time
from typing import Tuple,List,Any
from loguru import logger
from app.database.db_sqlite import async_db_session
from app.crud import station_crud
from app.crud import dev_crud
from app.models import Station,Dev
from app.schemas.station import RSStation

async def get_cvinfo_by_station_name(name:str)->Tuple[Station,Dev]:
    async with async_db_session() as db:
        station = await station_crud.get_station_by_name(db,name)
        dev = await dev_crud.get_dev_by_id(db,station.dev_id)
        return station,dev


async def get_stations()->List[RSStation]:
    async with async_db_session() as db:
        all_station = []
        stations = await station_crud.get_stations(db)
        for station in stations:
            dev = await dev_crud.get_dev_by_id(db,station.dev_id)
            attrs = vars(station)
            attrs.update({'dev_no':dev.dev_no,"dev_type":dev.type})
            all_station.append(attrs)
        return all_station